<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>My JSP 'spedt.jsp' starting page</title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

	</head>
	<script src="js/jquery.js"></script>
	<script>
	// 获得动植物下的子分类
		function getTypes(){
		var type = $("#maintype").val();
		$.getJSON("foodtype.do",{method:"getTypes",type1: type }, function(mytypes){
		$("#type2").html("<option >请选择类别</option>");
		for(i = 0;i<mytypes.length;i++){
		$("#type2").append("<option value="+mytypes[i].tpid+ "> "+ mytypes[i].tpcname+ "</option>");
		}
		}); 
		$("#addwindow").css("display","inline");
		$("#addwindow").html("<font color='gray' onclick='showadd()'>新增类型 -> > ></font>")
		}	
		
		function showadd(){
		$("#addwindow").html("<input type='text' id='addte'></input>"+
		"<a  onclick='comadd()' style='outline: 1px solid skyblue; '><strong>增加</strong></a>");
		}
		function comadd(){
		var type = $("#maintype").val();
		var subtype = $("#addte").val();		
		$.getJSON("foodtype.do",{method:"addType",styname: type,tpcname: subtype}, function(typ){
		}); 
		alert("新增成功！");
		getTypes();
		}
		function hidenAdd(){
		$("#addwindow").css("display","none");
		}
		
		function  checkText(){
		var image = document.myform.imgfile.value;		
		var shuju = document.myform.ftypecname.value;
		var leibie = document.myform.type2.value;
		var mingzi = document.myform.fname.value;
		var jianjie = document.myform.fintroduce.value;
		var gongxiao = document.myform.fefficacy.value;
		var yinyang = document.myform.fnutrition.value;
		if(shuju == ""){
		alert("请选择数据类型");
		return false;
		}
		if(leibie == ""){
		alert("请选择营养类型");
		return false;
		}
		if(mingzi == ""){
		alert("食品名字不能为空");
		return false;
		}
				
		if(image == ""){
		alert("请选择食物图片");
		return false;
		}
		
		if(jianjie == ""){
		alert("食品简介不能为空");
		return false;
		}
		if(gongxiao == ""){
		alert("食品功效不能为空");
		return false;
		}
		if(yinyang == ""){
		alert("营养成分不能为空");
		return false;
		}
		return true;
		}
		</script>
	<body>
		<center>
			<form method=post action=foods.do?method=addFood name="myform" onsubmit="return checkText()" enctype="multipart/form-data">
				<TABLE border=0 cellSpacing=1 cellPadding=0 width=800
					bgColor=#9bc8eb>
					<TBODY>
						<TR>
							<TD class=jj_r_5 bgColor=#eefbfe height=33 vAlign=center
								width=100 align=right>
								营养数据
								<FONT color=#ff0000>*</FONT>
							</TD>
							<TD class=jj_l_5 bgColor=#eefbfe height=33 vAlign=center
								width=341 colSpan=2 align=left>
								<select name="ftypecname"  id="maintype" onchange="getTypes()">
									<option value="">
										请选择类型
									</option>
									<option value="plant">
										植物篇
									</option>
									<option value="animal">
										动物篇
									</option>
								</select>
							</TD>
						</TR>

						<TR>
							<TD class=jj_r_5 bgColor=#eefbfe height=33 vAlign=center
								width=100 align=right>
								类别
								<FONT color=#ff0000>*</FONT>
							</TD>
							<TD id="tdadd" class=jj_l_5 bgColor=#eefbfe height=33
								vAlign=center width=341 colSpan=2 align=left>
								<select id="type2" onchange="hidenAdd()" name=ftype>
									<option>
										请选择类别
									</option>
								</select>	
								&nbsp;	&nbsp;						
								<div id="addwindow" style="display: none;border: 1px solid green; background-color: red;" />
							</TD>
						</TR>
						<TR>
							<TD class=jj_r_5 bgColor=#eefbfe height=33 vAlign=center
								width=100 align=right>
								具体食物
								<FONT color=#ff0000>*</FONT>
							</TD>
							<TD class=jj_l_5 bgColor=#eefbfe height=33 vAlign=center
								width=341 colSpan=2 align=left>
								<INPUT class=jyts_bk2 size=10 type=text name=fname />
							</TD>
						</TR>
						<TR>
							<TD class=jj_r_5 bgColor=#eefbfe height=33 vAlign=center
								width=100 align=right>
								相关图片
								<FONT color=#ff0000>*</FONT>
							</TD>
							<TD class=jj_l_5 bgColor=#eefbfe height=33 vAlign=center
								width=341 colSpan=2 align=left>
								<!-- 上传图片 -->
								<INPUT TYPE="file" class="boxBorder" NAME="imgfile" size=20 />
							</TD>
						</TR>
						<TR>
							<TD class=jj_r_5 bgColor=#eefbfe height=33 vAlign=center
								width=100 align=right>
								简介
								<FONT color=#ff0000>*</FONT>
							</TD>
							<TD class=jj_l_5 bgColor=#eefbfe height=33 vAlign=center
								width=341 colSpan=2 align=left>
								<textarea rows="3" cols="80" name=fintroduce></textarea>
							</TD>
						</TR>
						<TR>
							<TD class=jj_r_5 bgColor=#eefbfe height=33 vAlign=center
								width=100 align=right>
								保健功效
								<FONT color=#ff0000>*</FONT>
							</TD>
							<TD class=jj_l_5 bgColor=#eefbfe height=33 vAlign=center
								width=341 colSpan=2 align=left>
								<textarea rows="3" cols="80" name=fefficacy></textarea>
							</TD>
						</TR>
						<TR>
							<TD class=jj_r_5 bgColor=#eefbfe height=33 vAlign=center
								width=100 align=right>
								食用提示
								<FONT color=#ff0000>*</FONT>
							</TD>
							<TD class=jj_l_5 bgColor=#eefbfe height=33 vAlign=center
								width=341 colSpan=2 align=left>
								<textarea rows="3" cols="80" name=fclew></textarea>
							</TD>
						</TR>
						<TR>
							<TD class=jj_r_5 bgColor=#eefbfe height=33 vAlign=center
								width=100 align=right>
								营养成分
								<FONT color=#ff0000>*</FONT>
							</TD>
							<TD class=jj_l_5 bgColor=#eefbfe height=33 vAlign=center
								width=341 colSpan=2 align=left>
								<textarea rows="3" cols="80" name=fnutrition></textarea>
							</TD>
						</TR>
						<TR>
							<TD class=jj_r_5 bgColor=#eefbfe height=33 vAlign=center
								width=100 align=right>
								相关食谱
								<FONT color=#ff0000>*</FONT>
							</TD>
							<TD class=jj_l_5 bgColor=#eefbfe height=33 vAlign=center
								width=341 colSpan=2 align=left>
								<textarea rows="3" cols="80" name=fcookbook></textarea>
							</TD>
						</TR>
						<TR>
							<TD class=jj_r_5 bgColor=#eefbfe height=33 vAlign=center
								width=100 align=center colspan="2">
								<input type="submit" value="确认添加">
							</TD>
						</TR>
					</TBODY>
				</TABLE>
			</form>
		</center>
	</body>
</html>
